package com.aitou.mrylive.presentation.ui.main.find.pengyouquan;

import com.aitou.mrylive.data.bean.BaseResponse;
import com.aitou.mrylive.presentation.ui.base.BaseObserver;
import com.aitou.mrylive.presentation.ui.base.BasePresenter;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by admin on 2016/9/22.
 */
public class PublishPresenter extends BasePresenter<PublishInterFace> {

    PublishManager publishManager;
    public PublishPresenter(PublishInterFace uiInterface) {
        super(uiInterface);
        publishManager=new PublishManager();
    }

    public void publish(String token,String content,String pics ){
        Subscription subscription = publishManager.publish(token, content, pics)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<PublishBean>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<PublishBean> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showPublishResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }

    public void updatePublish(String token,String pid,String content,String pics ){
        Subscription subscription = publishManager.updatePublish(token, pid, content, pics)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<String>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showUpdatePublishResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }
    public void deletePublish(String token,String pid){
        Subscription subscription = publishManager.deletePublish(token, pid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<String>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showDeletePublishResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }
    public void dianzan(String token,String pid,String isLike){
        Subscription subscription = publishManager.dianzan(token, pid, isLike)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<String>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showdianzanResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }
    public void replyOne(String token,String pid,String content){
        Subscription subscription = publishManager.replyOne(token, pid, content)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<PublishBean>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<PublishBean> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showHuiFuOneResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }

    public void replyTwo(String token,String rid,String content){
        Subscription subscription = publishManager.replyTwo(token, rid, content)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<PublishBean>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<PublishBean> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showHuiFuOneResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }

    public void replyDelete(String token,String rid){
        Subscription subscription = publishManager.replyDelete(token, rid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<String>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
//                        LocalDataManager.getInstance().saveLoginInfo(response.getData());
                        getUiInterface().showReplyDeleteResult(response.getData());
//                        getUiInterface().startActivityAndFinishOthers();
                    }
                });
        addSubscription(subscription);
    }
}
